// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch
{
	public sealed partial class RemoteSource
	{
		[JsonInclude]
		[JsonPropertyName("connect_timeout")]
		public Elastic.Clients.Elasticsearch.Duration? ConnectTimeout { get; set; }

		[JsonInclude]
		[JsonPropertyName("headers")]
		public Dictionary<string, string>? Headers { get; set; }

		[JsonInclude]
		[JsonPropertyName("host")]
		public string Host { get; set; }

		[JsonInclude]
		[JsonPropertyName("password")]
		public string? Password { get; set; }

		[JsonInclude]
		[JsonPropertyName("socket_timeout")]
		public Elastic.Clients.Elasticsearch.Duration? SocketTimeout { get; set; }

		[JsonInclude]
		[JsonPropertyName("username")]
		public Elastic.Clients.Elasticsearch.Username? Username { get; set; }
	}

	public sealed partial class RemoteSourceDescriptor : SerializableDescriptorBase<RemoteSourceDescriptor>
	{
		internal RemoteSourceDescriptor(Action<RemoteSourceDescriptor> configure) => configure.Invoke(this);
		public RemoteSourceDescriptor() : base()
		{
		}

		private Elastic.Clients.Elasticsearch.Duration? ConnectTimeoutValue { get; set; }

		private Dictionary<string, string>? HeadersValue { get; set; }

		private string HostValue { get; set; }

		private string? PasswordValue { get; set; }

		private Elastic.Clients.Elasticsearch.Duration? SocketTimeoutValue { get; set; }

		private Elastic.Clients.Elasticsearch.Username? UsernameValue { get; set; }

		public RemoteSourceDescriptor ConnectTimeout(Elastic.Clients.Elasticsearch.Duration? connectTimeout)
		{
			ConnectTimeoutValue = connectTimeout;
			return Self;
		}

		public RemoteSourceDescriptor Headers(Func<FluentDictionary<string, string>, FluentDictionary<string, string>> selector)
		{
			HeadersValue = selector?.Invoke(new FluentDictionary<string, string>());
			return Self;
		}

		public RemoteSourceDescriptor Host(string host)
		{
			HostValue = host;
			return Self;
		}

		public RemoteSourceDescriptor Password(string? password)
		{
			PasswordValue = password;
			return Self;
		}

		public RemoteSourceDescriptor SocketTimeout(Elastic.Clients.Elasticsearch.Duration? socketTimeout)
		{
			SocketTimeoutValue = socketTimeout;
			return Self;
		}

		public RemoteSourceDescriptor Username(Elastic.Clients.Elasticsearch.Username? username)
		{
			UsernameValue = username;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (ConnectTimeoutValue is not null)
			{
				writer.WritePropertyName("connect_timeout");
				JsonSerializer.Serialize(writer, ConnectTimeoutValue, options);
			}

			if (HeadersValue is not null)
			{
				writer.WritePropertyName("headers");
				JsonSerializer.Serialize(writer, HeadersValue, options);
			}

			writer.WritePropertyName("host");
			JsonSerializer.Serialize(writer, HostValue, options);
			if (PasswordValue is not null)
			{
				writer.WritePropertyName("password");
				JsonSerializer.Serialize(writer, PasswordValue, options);
			}

			if (SocketTimeoutValue is not null)
			{
				writer.WritePropertyName("socket_timeout");
				JsonSerializer.Serialize(writer, SocketTimeoutValue, options);
			}

			if (UsernameValue is not null)
			{
				writer.WritePropertyName("username");
				JsonSerializer.Serialize(writer, UsernameValue, options);
			}

			writer.WriteEndObject();
		}
	}
}